package com.sc.nft.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sc.nft.entity.EcologyHatchExchangeConf;
import com.sc.nft.entity.EcologyHatchExtraRewards;
import com.sc.nft.entity.vo.AdminUserCreatorInfoAllDao;
import com.sc.nft.mapper.EcologyHatchExtraRewardsMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author 朱梦晨
 * @Description:
 * @date 2024-09-24
 */
@Slf4j
@Repository
public class EcologyHatchExtraRewardsDao extends ServiceImpl<EcologyHatchExtraRewardsMapper, EcologyHatchExtraRewards> {
    public EcologyHatchExtraRewards getOpenByEcologyHatchId(Long ecologyHatchId) {
        LambdaQueryWrapper<EcologyHatchExtraRewards> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(EcologyHatchExtraRewards::getEcologyHatchId,ecologyHatchId);
        wrapper.eq(EcologyHatchExtraRewards::getStatus,Boolean.TRUE);
        wrapper.last("order by id desc limit 1");
        return getOne(wrapper);
    }


    public boolean updateEcologyHatchExtraRewardsById(Long id, Boolean status,String extraRuleRemarkImg) {
        LambdaUpdateWrapper<EcologyHatchExtraRewards> wrapper = new LambdaUpdateWrapper<>();
        wrapper.eq(EcologyHatchExtraRewards::getId, id);
        wrapper.set(EcologyHatchExtraRewards::getStatus, status);
        wrapper.set(EcologyHatchExtraRewards::getExtraRuleRemarkImg, extraRuleRemarkImg);
        return update(new EcologyHatchExtraRewards(), wrapper);
    }



    /**
     * 获取额外奖励关联表
     *
     * @param ecologyHatchId
     * @return
     */
    public EcologyHatchExtraRewards getOneByEcologyHatchId(Long ecologyHatchId) {
        LambdaQueryWrapper<EcologyHatchExtraRewards> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(EcologyHatchExtraRewards::getEcologyHatchId, ecologyHatchId);
        wrapper.eq(EcologyHatchExtraRewards::getIsDelete, Boolean.FALSE);
        return getOne(wrapper);
    }


    /**
     * 获取所有额外奖励配置
     * @return
     */
    public List<EcologyHatchExtraRewards> getAll() {
            return baseMapper.getAll();
        }

}
